package make.money.Files;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class FileUtils {

    /**
     * 读取文件中的数据并返回每行的数据
     * @param path
     * @return
     * @throws Exception
     */
    private static List<String> readFileList(String path) throws Exception{
        System.out.println("======读取文件中=======");
        List<String> newString = new ArrayList<>();
        Thread.sleep(1000);
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(path));
            String line;
            while ((line = reader.readLine()) != null) {
                // 处理读取到的每一行数据
                newString.add(line);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return newString;
    }
    /**
     * 判断文件是否存在不存在就创建它
     */
    public static void createFile(String filePath) throws Exception{
        File file =new File(filePath);
        if(file.exists()){
            file.delete();
        }
        file.createNewFile();
    }
}
